package com.dd.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dd.entity.DdSms;



public class DdSmsDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(DdSmsDAO.class);


	public void saveOrUpdate(DdSms transientInstance) {
		log.debug("saving DdSms instance");
		try {
			getHibernateTemplate().saveOrUpdate(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(DdSms persistentInstance) {
		log.debug("deleting DdSms instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public DdSms findById(java.lang.Integer id) {
		log.debug("getting DdSms instance with id: " + id);
		try {
			DdSms instance = (DdSms) getHibernateTemplate().get(
					"com.dd.entity.DdSms", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public DdSms findByMsgId(java.lang.Integer msgid) {
		
		try {
			List li = getHibernateTemplate().find("from DdSms where msgid="+msgid);
			if(li.size()>0){
				return (DdSms)li.get(0);
			}else{
				return null;
			}
		} catch (RuntimeException re) {
			log.error("get failed", re);
			return null;
		}
	}
	public List findByOrderid(java.lang.Integer ordid) {
		log.debug("findByStatus");
		try {
			return getHibernateTemplate().find("from DdSms where orderid="+ordid);
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public List findByStatus(java.lang.Integer status) {
		log.debug("findByStatus");
		try {
			return getHibernateTemplate().find("from DdSms where status="+status);
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public List findToSend() {
		log.debug("findByStatus");
		try {
			return getHibernateTemplate().find("from DdSms where status=0 order by id");
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public List findToSendForMas() {
		log.debug("findByStatus");
		try {
			return getHibernateTemplate().find("from DdSms where masstatus=0 order by id");
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
}